<template>
  <el-select
    v-model="selectedCollId"    
    clearable
    filterable
    reserve-keyword
    placeholder="请选择活动"
    :loading="loading"
    size="small"
    @change="handleChange"
  >
    <el-option
      v-for="item in collList"
      :key="item.value"
      :label="item.label"
      :value="item.value">
    </el-option>
  </el-select>
</template>

<script>
import api from '@/common/api'
import {isArray} from "xe-utils";

export default {
  name: 'CollSelect',
  props: {
    value: {
      type: String,
      default: null
    },
    widthFixed: {
      type: Boolean,
      default: false
    },
    initSelectFirst: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      collList: [],
      loading: false,
      selectedCollId: '',
    }
  },
  watch: {
    value: {
      immediate: true,
      handler(newVal) {
        this.selectedCollId = newVal
      }
    }
  },
  computed: {},
  mounted() {
    this.loadData()
  },
  methods: {
    async loadData() {
      try {
        const { data } = await api.admin_getItechCollOptions()
        if (data.data.length > 0) {
          this.collList = data.data
        }
      } catch (error) {
        this.$message.error('获取活动信息失败')
      }
    },
    handleChange(val) {
      let value = val

      this.$emit('input', value);
      this.$emit('change', value)
    }
  }
}
</script>

<style scoped>

</style>
